package com.cmeduSystem.common.online.script;

import com.cmeduSystem.common.core.object.MyPageParam;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.annotations.JSConstructor;
import org.mozilla.javascript.annotations.JSFunction;

/**
 * MyPageParam的JavaScript转换器
 *
 * @author xulei
 * @date 2025-09-04
 */
public class JsPageParam extends ScriptableObject {

    private final MyPageParam pageParam;

    @Override
    public String getClassName() {
        return "MyPageParam";
    }

    @JSConstructor
    public JsPageParam() {
        this.pageParam = new MyPageParam();
    }

    @JSConstructor
    public JsPageParam(int pageNum, int pageSize) {
        this.pageParam = new MyPageParam(pageNum, pageSize);
    }

    @JSFunction
    public Integer getPageNum() {
        return pageParam.getPageNum();
    }

    @JSFunction
    public void setPageNum(int pageNum) {
        pageParam.setPageNum(pageNum);
    }

    @JSFunction
    public Integer getPageSize() {
        return pageParam.getPageSize();
    }

    @JSFunction
    public void setPageSize(int pageSize) {
        pageParam.setPageSize(pageSize);
    }

    public MyPageParam unwrap() {
        return pageParam;
    }

    /**
     * 将MyPageParam类转换为JavaScript构造函数
     */
    public static void convertToJsConstructor(Scriptable scope) {
        try {
            // 使用defineClass方法将MyPageParam类暴露给JavaScript
            ScriptableObject.defineClass(scope, JsPageParam.class);
        } catch (Exception e) {
            throw new RuntimeException("Failed to define MyPageParam class in JavaScript: " + e.getMessage(), e);
        }
    }
}